package indi.woniu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import indi.woniu.entity.*;
import indi.woniu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/findAll")
    public ResponseEntity findAll(){
        List<Student> list = studentService.findAll();
        return new ResponseEntity(200,"成功",list);
    }
    @RequestMapping("/showGradeByUserId")
    public ResponseEntity showGradeByUserId( @RequestBody Form form ){
        PageHelper.startPage(form.getPage(),form.getLimit());
        List<TestGrade> list = studentService.showGradeByUserId(form.getUserId());
        PageInfo<TestGrade> pageInfo = new PageInfo<>(list);
        return new ResponseEntity(200,"查询成功",pageInfo);

    }
    @PostMapping("/showAnswer/{paperId}")
    public ResponseEntity showAnswer(@PathVariable int paperId){
        Map map = studentService.showAnswer(paperId);
        return new ResponseEntity(200,"成功",map);
    }
}
